package com.cyrus.vueboot.error;

import com.cyrus.vueboot.common.R;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Author: Cyrus
 * @CreateDate: 2020/12/6
 */
@ControllerAdvice
public class GlobalException {
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public R errorGlobal(BusinessError e) {
        return R.error().message("全局异常拦截");
    }

    @ExceptionHandler(BusinessError.class)
    @ResponseBody
    public R error(BusinessError e) {
        return R.error().code(e.getCode()).message(e.getMsg());
    }
}
